/*
package com.gxa.uhome.controller;

import com.gxa.uhome.exception.BusinessException;
import com.gxa.uhome.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@ControllerAdvice
class ExceptionController {

   */
/* @ExceptionHandler(BusinessException.class)
    public void businesshandler(){

    }
    @ExceptionHandler(Exception.class)
    public void exceptionhandler(){

    }*//*


    @ExceptionHandler(Throwable.class)
    @ResponseBody
    public JsonResult throwablehandler(Exception e) throws IOException {
        JsonResult jsonResult = new JsonResult();
        System.out.println("e:" + e);
        if (e instanceof BusinessException) {
            // 给前端返回消息:
            // code: 0/1
            // status: 400:参数类型或数量不匹配
            //404: 资源找不到
            //405: GET/POST 类型不匹配
            //500 : 自查
            // msg
            jsonResult.setCode("0");
            jsonResult.setMsg(e.getMessage());

        } else {
            System.out.println(e);
            Date date = new Date();
            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("YYYY-MM-dd");
            SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
            String format1 = simpleDateFormat1.format(date);
            String format2 = simpleDateFormat2.format(date);

            StringBuilder stringBuilder = new StringBuilder();
            String folderPath = "D:" + File.separator + "log";
            String filePath = "D:" + File.separator + "log" + File.separator + format1 + "errorLog" + ".log";

            File folder = new File(folderPath);
            File file = new File(filePath);
            if(!folder.exists()){
                folder.mkdir();
            }
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fileWriter = new FileWriter(filePath, true);
            stringBuilder.append("*******************************" + "异常日志"+"********************************" + "\r\n");
            stringBuilder.append(format2 + "   "+"error" + "\r\n");
            stringBuilder.append("错误信息："+e.getMessage()+"\r\n");
            StackTraceElement[] stackTrace = e.getStackTrace();
            stringBuilder.append("错误路径信息：");
            for(StackTraceElement element : stackTrace){
                stringBuilder.append(element.toString()+"\r\n");
            }

            stringBuilder.append("\r\n");

            fileWriter.write(stringBuilder.toString());
            fileWriter.flush();
            fileWriter.close();
            jsonResult.setCode("0");
            jsonResult.setMsg("未知异常，请联系管理员");
        }
        return jsonResult;
    }

}
*/
